#!/bin/bash

echo "set terminal png" >$1/qps.p
echo "set output '$1/qps.png'" >>$1/qps.p
echo "set title 'Comparison of QPS with different settings'" >>$1/qps.p
echo "set grid y" >>$1/qps.p
echo "set boxwidth 0.5" >>$1/qps.p
echo "set style fill solid" >>$1/qps.p
echo "set xtics rotate" >>$1/qps.p
echo "plot '$1/qps.gnuplot.out' using 2:xticlabels(1) notitle with boxes" >>$1/qps.p

echo >$1/qps.gnuplot.out
for entry in `find $1/ -name "*.out" -not -name "*.gnuplot.out"`
do
  echo $entry
  testname=`basename $entry`

  qps=`grep "Requests per second" $entry | awk -F' ' '{print $4}'`

  if [ -z $qps ]; then
    qps=0
  fi

  echo "$testname $qps" >> $1/qps.gnuplot.out
done

gnuplot $1/qps.p

